<?php
$this->breadcrumbs = array (
		'Jogadores' => array (
				'index' 
		),
		$model->category->team->name => array (
				'/team/view',
				'id' => $model->category->team_id 
		),
		$model->name 
);

$files = File::model ()->findAllByAttributes ( array (
		'type' => "PLAYER",
		'relation_id' => $model->id 
) );
$file_list = array ();
foreach ( $files as $file ) {
	$file_list [] = array (
			'label' => $file->filename,
			'url' => array (
					'file',
					'filename' => $file->filename,
					'url' => $file->url 
			),
			'visible' => $_SESSION ['user']->username == 'admin' || $model->category->team->owner_id == $_SESSION ['owner']->id 
	);
}

$this->files = $file_list;

$this->menu = array (
		array (
				'label' => 'Listar Jogadores',
				'url' => array (
						'index' 
				) 
		),
		array (
				'label' => 'Inserir Jogador',
				'url' => array (
						'create',
						'team_id' => $model->category->team_id,
						'return_url' => '/team/view/' . $model->category->team_id 
				) ,
				'visible' => $_SESSION ['user']->username == 'admin' || ($_SESSION ['owner']->id == $model->category->team->owner_id),
		),
		array (
				'label' => 'Alterar Dados do Jogador',
				'url' => array (
						'update',
						'id' => $model->id 
				),
				'visible' => false && ($_SESSION ['user']->username == 'admin' || $_SESSION ['owner']->id == $model->category->team->owner_id) 
		),
		array (
				'label' => 'Aprovar Cadastro do Jogador',
				'url' => '#',
				'visible' => $_SESSION ['user']->username == 'admin' && $model->status != 'ATIVO',
				'linkOptions' => array (
						'submit' => array (
								'approve',
								'id' => $model->id 
						),
						'confirm' => 'Deseja realmente aprovar os dados do Jogador?' 
				) 
		),
		array (
				'label' => 'Solicitar Transferência do Jogador',
				'url' => array (
						'transference/create',
						'player_id' => $model->id 
				),
				'visible' => isset( $_SESSION ['owner'] ) 
				&& Team::model()->findByAttributes ( array ('owner_id' => $_SESSION ['owner']->id) ) != null 
				&& $model->status != 'ATIVO'
				&& $model->category->team->owner_id != $_SESSION ['owner']->id 
				&& Transference::model ()->findByAttributes ( array (
						'status' => 'Em Andamento',
						'player' => $model->id,
						'team_buyer_id' => Team::model ()->findByAttributes ( array (
								'owner_id' => $_SESSION ['owner']->id 
						) )->id 
				) ) == null
		),
		array('label'=> 'Revalidar Jogador',
				'url' => '#',
				'linkOptions' => array (
						'submit' => array (
								'revalidate',
								'id' => $model->id
						),
						'confirm' => 'Deseja realmente revalidar os dados do Jogador?'
				),
				'visible'=>$model->status == 'ATIVO' && !$this->isRevalidated($model)  && ($_SESSION['user']->username == 'admin' ||
				$model->category->team->owner_id == $_SESSION ['owner']->id),
));

$photo = Utils::getPlayerPhoto ( $model );

?>

<?php

if (strtoupper($model->status) == strtoupper("EM APROVAÇÃO")) {
	echo '<h4 align="right" style="color:orange;">' . $model->status . '</h4>';
}
?>

<table>
	<tr>
		<td>
	<?php echo CHtml::image(Utils::findImageUrl($photo[0]->filename),$model->name,array('width'=>100,'height'=>140)); ?>
</td>
		<td style="min-width: 500px;">
			<h1 align="center"><?php echo $model->name; ?></h1>
		</td>
	</tr>
</table>

<?php

$this->widget ( 'bootstrap.widgets.TbDetailView', array (
		'data' => $model,
		'attributes' => array (
				'name',
				array (
						'label' => 'Time',
						'value' => $model->category->team->name 
				),
				array (
						'label' => 'Data de Registro',
						'value' => Utils::changeDate ( $model->registry_date ) 
				),
				'natural_country',
				'natural_state',
				'natural_city',
				'nickname',
				array (
						'label' => 'Data de Nascimento',
						'value' => Utils::changeDate ( $model->birthy_date ) 
				),
				array ( 'label' => 'Sexo',
						'value' => $model->gender == 0 ? 'Masculino' : 'Feminino'
				),
				
				'father_name',
				'mother_name',
				'email',
				'address',
				'neightborhood',
				'state',
				'city',
				'cert_birthy',
				'rg',
				'emissor',
				'doc_validate',
				'cpf',
				'ctps',
				'cnh',
	),
)); ?>
